home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
PROBLEMS
/
BENCHMARK
/
BUBBLESORT
/
bubbletest
/
assembler2
/
needed
< prev
next >
Wrap
Text File
|
1992-05-13
|
12KB
|
642 lines
; ****************************************************************************
; This file is freeware, you may copy it, but not modify and/or make money
; with it
; the contence is a conclusion of !formula.tlastatrel and !formula.functions
; formula is freeware
; it's publiced here for people, who don't have, don't want formula
; ****************************************************************************
stackregister .EQU R12
tempregister .EQU R11
formulastackregistersave .EQU FALSE
formulatempregistersave .EQU FALSE
formulaflagsave .EQU FALSE
formulastacklength .EQU 256.
; used macros following
.MACRO LADR
\adress
.IF \adress- %2 >65524.
MOV %1,#((\adress - %2 + 8 + 12.) & 0FF)
ADD %1,%1,#(((\adress - %2 + 8 + 12.) / 100) &0FF) << 8
ADD %1,%1,#((\adress - %2 + 8 + 12.) / 10000) << 16.
.ELSE
MOV %1,#((\adress - %2 + 8 + 8) & 0FF)
ADD %1,%1,#(((\adress - %2 + 8 + 8) / 100) &0FF) << 8
.ENDC
SUB %1,PC,%1
.ENDM
.MACRO ADDR
\addr
.IF \addr- %2 >255.
LADR %1,%2
.ELSE
ADR %1,%2
.ENDC
.ENDM
.MACRO LD
\load
.IF \load- %2 >4084.
LADR %1,%2
LDR %1,[%1]
.ELSE
LDR %1,%2
.ENDC
.ENDM
.MACRO LDB
\load
.IF \load- %2 >4084.
LADR %1,%2
LDRB %1,[%1]
.ELSE
LDRB %1,%2
.ENDC
.ENDM
.MACRO ST
\store
.IF \store- %2 >4084.
LADR tempregister,%2
STR %1,[tempregister]
.ELSE
STR %1,%2
.ENDC
.ENDM
.MACRO STB
\store
.IF \store- %2 >4084.
LADR tempregister,%2
STRB %1,[tempregister]
.ELSE
STRB %1,%2
.ENDC
.ENDM
.MACRO BACKADDR
LDR tempregister,\goadress
ADD %1,PC,tempregister
B \ready
\goadress .WORD %2-\goadress
\ready
.ENDM
.MACRO formuladata
; stackspace for the stack of formula
; Invoke this only one time !!!!
B formulajump
formulatemp .BLOCK formulastacklength,0
.ALIGN
formularegistersave .BLOCK 64.
.ALIGN
formulaclitail .BLOCK 257.,0
.ALIGN
formulamystackregistersave .WORD 0
formulajump
formula_one .EQU 1
.ENDM
; initialisation for formula, MUST be called before the first formulacommand
; change values of stackregister and tempregister
.MACRO formulainit
LADR stackregister,formulatemp
LADR tempregister,formulamystackregistersave
STR stackregister,[tempregister]
STR stackregister,[stackregister,#4]
.ENDM
formuladata
formulainit
.NOLIST
.MACRO GO
B %1
.ENDM
.MACRO GOLINK
BL %1
.ENDM
.MACRO GOcond
B%1 %2
.ENDM
.MACRO saveregister
.IF formulastackregistersave
.IF formulatempregistersave
STR tempregister,\tempregistersave
.ENDC
LD tempregister,formulamystackregistersave
STR stackregister,[tempregister,#4]
MOV stackregister,tempregister
.ENDC
.IF formulaflagsave
MOV tempregister,R15
AND tempregister,tempregister,#0FC << 24.
STR tempregister,[stackregister,#8]
.ENDC
.IF formulatempregistersave
.IF formulastackregistersave
LDR tempregister,\tempregistersave
GO \hupf
\tempregistersave .WORD 0
\hupf
.ENDC
STR tempregister,[stackregister,#0]
.ENDC
.ENDM
.MACRO restoreregister
.IF formulaflagsave
LDR tempregister,[stackregister,#8]
TEQP R15,#0FC << 24.
TEQP R15,tempregister
.ENDC
.IF formulatempregistersave
LDR tempregister,[stackregister,#0]
.ENDC
.IF formulastackregistersave
LDR stackregister,[stackregister,#4]
.ENDC
.ENDM
.MACRO STACKadd
INTsum %1,%2,#%3
.IF formulastackregistersave
ST stackregister,formulamystackregistersave
.ENDC
.ENDM
.MACRO STACKsub
INTsubtract %1,%2,#%3
.IF formulastackregistersave
ST stackregister,formulamystackregistersave
.ENDC
.ENDM
.MACRO DEFSTORE
%1 .BLOCK %2,%3
.ALIGN
.ENDM
; division routine
; 1. calculate flag if result is negate and convert operands to positiv
; 2. second "divide" with unsigned suczessive Approximation
; 3. fix the sign of result
.MACRO INTdivide_mac
STR %2,\arg2save
STR %3,\arg3save
MOV tempregister,#0
CMP %2,#0
RSBLT %2,%2,#0
SUBLT tempregister,tempregister,#1
CMP %3,#0
RSBLT %3,%3,#0
MVNLT tempregister,tempregister
STR tempregister,\sign
MOV tempregister,#0
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
ADDS %2,%2,%2
ADCS tempregister,tempregister,tempregister
CMP tempregister,%3
SUBGE tempregister,tempregister,%3
ADDGE %2,%2,#1
LDR tempregister,\sign
CMP tempregister,#0
RSBNE %2,%2,#0
MOV tempregister,%2
LDR %2,\arg2save
LDR %3,\arg3save
MOV %1,tempregister
GO \hupf
\arg2save .WORD 0
\arg3save .WORD 0
\sign .WORD 0
\hupf
.ENDM
.MACRO INTconstlongload
LDR %1,\temp
GO \jump2
\temp .WORD %2
\jump2
.ENDM
.MACRO INTconstload
.IF 100<%2
INTconstlongload %1,%2
.ELSE
.IF 0>%2
INTconstlongload %1,%2
.ELSE
MOV %1,#%2
.ENDC
.ENDC
.ENDM
.MACRO INTsum
ADD %1,%2,%3
.ENDM
.MACRO INTsubtract
SUB %1,%2,%3
.ENDM
.MACRO INTconstmult
.IF %2<>1
.IF %2=4
MOV %1,%1,ASL #2
.ELSE
MOV tempregister,%1
MUL %1,tempregister,#%2
.ENDC
.ENDC
.ENDM
.MACRO INTmodulo
STR %2,\temp2
STR %3,\temp3
INTdivide_mac %1,%2,%3
MOV tempregister,%1
LDR %2,\temp2
LDR %3,\temp3
MUL tempregister,%3,tempregister
SUB %1,%2,tempregister
B \ready
\temp2 .WORD 0
\temp3 .WORD 0
\ready
.ENDM
.MACRO INTregstore
MOV %1,%2
.ENDM
.MACRO INTarraystore
STR %2,[%1]
.ENDM
.MACRO INTarrayload
LDR %2,[%1]
.ENDM
.MACRO INTgreater
CMP %2,%3
MOVGT %1,#1
MOVLE %1,#0
.ENDM
.MACRO INTless
CMP %2,%3
MOVLT %1,#1
MOVGE %1,#0
.ENDM
.MACRO INTstackload
LDR %1,%2,%3
.ENDM
.MACRO INTstackstore
STR %3,%1,%2
.ENDM
.MACRO STRINGconstload
GO \hupf
\adress .STRING %2
.ALIGN
.WORD 0
\hupf
ADR %1,\adress
.ENDM
.MACRO INTPTRconstload
ADDR %1,%2
.ENDM
.MACRO INTPTRstackload
LDR %1,%2,%3
.ENDM
.MACRO INTPTRstackstore
STR %3,%1,%2
.ENDM
.MACRO CHARPTRstackstore
STR %3,%1,%2
.ENDM
.MACRO ifnotgoto
CMP %2,#0
GOcond EQ,%1
.ENDM
.MACRO goto
GO %1
.ENDM
.ALIGN
.LIST
;routines to check errors after a SWI via the V-flag
B formulafunctionstart
errorcheckflag .EQU TRUE
; error, if errorflag==1
; no error, if errorflag==0
; DECLARE INT errorflag
errorflag .WORD 0
; RiscOS errorblock
; DECLARE CHARPTR errorblock
errorblock .WORD 0
formulaerrorcheck
BVS formulaerror
MOV tempregister,#0
STR tempregister,errorflag
B formulaerrorback
formulaerror
STR R0,errorblock
MOV tempregister,#1
STR tempregister,errorflag
formulaerrorback
MOV PC,R14
MOV R0,R0
formulafunctionstart
.MACRO errorcheck
.IF errorcheckflag
STR R14,\temp
BL formulaerrorcheck
LDR R14,\temp
B \ready
\temp .WORD 0
\ready
.ENDC
.ENDM
.MACRO perror
LD tempregister,errorflag
CMP tempregister,#1
BNE \ready
STR R0,\formulatemp0
LD R0,errorblock
ADD R0,R0,#4
SWI XOS_Write0
SWI XOS_NewLine
LDR R0,\formulatemp0
B \ready
\formulatemp0
\ready
.ENDM
;Macro to convert integer %2 to string %1 destroy R0,R1,R2,R3,R4
.MACRO int2stringmacro
GO \hupf
\buffer .BLOCK 12.
.ALIGN
\hupf
ADR R4,\buffer
MOV R2,#11.
MOV R0,%2
MOV R1,R4
SWI XOS_BinaryToDecimal
errorcheck
MOV R3,#0
STRB R3,[R4,R2]
MOV %1,R4
.ENDM
; DECLARE INT writeint(INT number)
.MACRO writeint
LDR R5,[stackregister,#%2]
int2stringmacro R0,R5
SWI XOS_Write0
; errorcheck
.ENDM
; DECLARE INT system(CHARPTR cli_string)
.MACRO system
LDR R0,[stackregister,#%2]
SWI XOS_CLI
errorcheck
.ENDM
; DECLARE INT cr()
.MACRO cr
SWI XOS_NewLine
; errorcheck
.ENDM